home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / news / thor / rexx / runcommand.br < prev    next >
Text File  |  1998-05-24  |  3KB  |  144 lines

  1. /*
  2. ** $VER: RunCommand.br 1.3 (28.8.95)
  3. **
  4. ** Intended for use as an SortMail external script, but can be used from the
  5. ** Shell as well.  Also servers as an example of how to create external
  6. ** scripts for SortMail.
  7. **
  8. ** See SortMail.guide for documentation
  9. **
  10. */
  11.  
  12. /*
  13. ** INITIALIZATION
  14. */
  15.  
  16. options results
  17.  
  18. signal on syntax
  19. signal on break_c
  20. signal on halt
  21.  
  22. options failat 30
  23.  
  24. parse arg arguments                      /* Get command line arguments */
  25.  
  26. template = 'COMMAND/A,OPTIONS/K,ASYNC/S' /* READARGS template */
  27.  
  28. /*
  29. ** See if I'm run from Thor.  If true, fromthor = 1 and thorport is Thor's
  30. ** ARexx port, otherwise fromthor = 0
  31. */
  32.  
  33. thorport = getclip('SM_ThorPort')
  34. if thorport ~= '' then do
  35.     fromthor = 1
  36.     end
  37. else fromthor = 0
  38.  
  39. /*
  40. ** Check if BBSREAD's ARexx port is open, open it if it's not
  41. */
  42.  
  43. if ~show('P', 'BBSREAD') then do
  44.     address(command)
  45.     'Run >NIL: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  46.     'WaitForPort BBSREAD'
  47.     if rc ~= 0 then do
  48.         say 'Couldn''t open BBSREAD''s ARexx port.'
  49.         exit(20)
  50.         end
  51.     end
  52.  
  53. /*
  54. ** Parse command line
  55. */
  56.  
  57. args.ASYNC = 0                         /* Switches are set to 0 so if tests can
  58.                                           be performed on them, like below */
  59. address(bbsread)
  60. 'READARGS 'template args' CMDLINE 'arguments
  61. if rc ~= 0 then do
  62.     say 'READARGS failed: 'BBSREAD.LASTERROR
  63.     exit(rc)
  64.     end
  65.  
  66. /*
  67. ** MAIN CODE - substitute with your own
  68. */
  69.  
  70. /*
  71. ** Create the command line
  72. */
  73.  
  74. if args.ASYNC then
  75.     cmdline = 'Run >NIL: "' || args.COMMAND || '" >T:RunCommand.out'
  76. else
  77.     cmdline = '"' || args.COMMAND || '" >T:RunCommand.out'
  78.  
  79. if symbol('args.OPTIONS') = 'VAR' then
  80.     cmdline = cmdline || ' ' || args.OPTIONS
  81.  
  82. /*
  83. ** Execute the command line
  84. */
  85.  
  86. address command cmdline
  87.  
  88. if rc ~= 0 then do
  89.     commandrc = rc
  90.     erropen = open(ef, 'T:RunCommand.out', 'R')
  91.     if erropen then do
  92.         say 'External script RunCommand.br failed: 'readln(ef)
  93.         call close(ef)
  94.         if exists('T:RunCommand.result') then
  95.             address command 'Delete "T:RunCommand.out" QUIET'
  96.         end
  97.     else
  98.         say 'External script RunCommand.br failed: Unknown error'
  99.     exit(commandrc)
  100.     end
  101.  
  102. /*
  103. ** Skip to cleanup: to do a clean exit
  104. */
  105.  
  106. signal cleanup
  107.  
  108.  
  109. /*
  110. ** ERROR HANDLING AND EXITING
  111. */
  112.  
  113. /*
  114. ** Error handling routine
  115. */
  116.  
  117. error:
  118. syntax:
  119.  
  120. /*
  121. ** Show BBSREAD, THOR or ARexx error
  122. */
  123.  
  124. select
  125.     when symbol('BBSREAD.LASTERROR') = 'VAR' then
  126.         say 'BBSREAD returned 'rc' in line 'sigl': 'BBSREAD.LASTERROR
  127.  
  128.     when symbol('THOR.LASTERROR')    = 'VAR' then
  129.         say 'THOR returned 'rc' in line 'sigl': 'THOR.LASTERROR
  130.  
  131.     otherwise say 'Error 'rc' in line 'sigl': 'errortext(rc)
  132.     end
  133.  
  134. /*
  135. ** Leave script, returning the proper error code (if any)
  136. */
  137.  
  138. cleanup:
  139. break_c:
  140. halt:
  141.  
  142. if symbol('rc') = 'VAR' then exit(rc)
  143. else exit(0)
  144.